<%@ page import="com.jr.pojo.Enterprise" %>
<%@ page import="com.jr.pojo.Users" %><%--
  Created by IntelliJ IDEA.
  User: 86139
  Date: 2025/8/31
  Time: 21:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>企业认证</title>
    <script type="text/javascript" src="js/jquery-1.8.3.js"></script>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Microsoft YaHei', Arial, sans-serif;
        }

        body {
            background-color: #f5f5f5;
            padding: 20px;
            color: #333;
        }

        .container {
            max-width: 1000px;
            margin: 0 auto;
            background: white;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 1px solid #eee;
        }

        .header h1 {
            font-size: 24px;
            font-weight: normal;
            color: #333;
        }

        .logout-link {
            color: #e74c3c;
            text-decoration: none;
            font-size: 14px;
        }

        .logout-link:hover {
            text-decoration: underline;
        }

        .section {
            margin-bottom: 25px;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 5px;
            background-color: #f9f9f9;
        }

        .section-title {
            font-size: 18px;
            margin-bottom: 15px;
            color: #2c3e50;
            font-weight: bold;
            padding-bottom: 8px;
            border-bottom: 1px solid #eee;
        }

        table {
            width: 100%;
            border-collapse: collapse;
        }

        table tr {
            border-bottom: 1px solid #eee;
        }

        table td {
            padding: 12px 8px;
            vertical-align: top;
        }

        table td:first-child {
            width: 30%;
            font-weight: bold;
            color: #555;
        }

        input[type="text"], select, textarea {
            width: 100%;
            padding: 10px 12px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 14px;
        }

        input[type="text"]:focus, select:focus, textarea:focus {
            outline: none;
            border-color: #4a90e2;
            box-shadow: 0 0 5px rgba(74, 144, 226, 0.3);
        }

        textarea {
            height: 100px;
            resize: vertical;
        }

        label {
            font-size: 12px;
            display: block;
            margin-top: 5px;
        }

        .button {
            padding: 10px 16px;
            background-color: #4a90e2;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            margin-right: 10px;
            margin-bottom: 10px;
        }

        .button:hover {
            background-color: #3a80d2;
        }

        .module {
            margin: 15px 0;
            padding: 15px;
            border: 1px solid #ddd;
            border-radius: 5px;
            background-color: white;
        }

        .user-info {
            font-size: 14px;
            margin-bottom: 15px;
            color: #666;
            padding: 10px;
            background-color: #f0f8ff;
            border-radius: 4px;
            border-left: 4px solid #4a90e2;
        }

        .submit-btn {
            padding: 12px 24px;
            background-color: #2ecc71;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            margin-top: 15px;
            display: block;
            width: 120px;
        }

        .submit-btn:hover {
            background-color: #27ae60;
        }

        .error {
            color: #e74c3c;
            font-size: 12px;
            margin-top: 5px;
        }

        .success {
            color: #2ecc71;
            font-size: 12px;
            margin-top: 5px;
        }

        .button-group {
            margin-top: 15px;
        }
    </style>
    <script type="text/javascript">
        /*定义错误正确信息颜色*/
        var _red = "red";
        var _green = "green";

        $(document).ready(function (u) {
            var account = $('em[name="account"]').text();
            //alert(account)
            /*通过输入的信息拿对象 获得对象的 姓名和身份证号*/
            $.get("userlogin/queryUserInfo", {'account': account}, function (users) {
                JSON.stringify(users)
                $("[name='userphone']").text(users.phone)

                $("[name='username'], [name='idcard']").blur(function () {
                    var username = $("[name='username']").val()
                    var idcard = $('[name="idcard"]').val();
                    /*判断用户输入的姓名和身份证号和该账号下的姓名和身份证号是否相同*/
                    if (username && idcard) {
                        if (username == users.cardname && idcard == users.cardnum) {
                            alert("身份验证成功！")
                        } else {
                            alert("身份验证失败！！")
                        }
                    }
                })
            })

            /*点击要跳转功能，进入新的页面*/
            $('[name="whitebutton"]').click(function () {
                window.location.href = "white.jsp?account=" + $('[name="loginaccount"]').text();
            })

            $('[name="blackbutton"]').click(function () {
                window.location.href = "black.jsp?account=" + $('[name="loginaccount"]').text();
            })

            {
                // 方法1: 使用toggle()方法
                $("#toggleBtn").click(function () {
                    $("#targetModule").toggle();
                });

                // 方法1: 使用toggle()方法
                $("#showModuleBtn").click(function () {
                    $("#targetModule1").toggle();
                });
            }

            {
                /*控制企业信息 代码
                * 分为两部分 首先判断输入的企业名称是否存在 如果存在 当输入完企业名称时立刻回显数据*/
                $("[name='edirname']").blur(function () {
                    var edirname = $("[name='edirname']").val()
                    var label = $("#edirnamelabel")

                    if (edirname.trim().length != 0) {
                        $("#edirnamelabel").text(" ");
                        $("#edirnamelabel").css("color", _green);
                    } else {
                        $("#edirnamelabel").text("企业名称不允许为空！！请重新输入");
                        $("#edirnamelabel").css("color", _red);
                    }

                    if (edirname.trim().length != 0) {
                        $.get("subinfo/queryInfo", {'edirname': edirname}, function (boo) {
                            JSON.stringify(boo)
                            if (boo) {
                                $.get("subinfo/queryEnterByName", {'edirname': edirname}, function (enter) {
                                    /*向指定的文本框内添加由数据库和java传过来的信息 */
                                    $("[name='uniformcode']").val(enter.uniformcode)
                                    $("[name='email']").val(enter.email)
                                    $("[name='phone']").val(enter.phone)
                                    $("[name='fax']").val(enter.fax)
                                    $("[name='address']").val(enter.address)
                                    $("[value='scale']").val(enter.scale)
                                    $('select').find("option").each(function () {
                                        if ($(this).val() === enter.scale || $(this).text() === enter.scale) {
                                            $(this).prop("selected", true);
                                            return false;
                                        }
                                    });
                                    alert("回显成功！！")
                                })
                            } else {
                                $('[name="submitinfo"]').click(function () {
                                    var uniformcode = $("[name='uniformcode']").val()
                                    var scale = $("[name='scale']").val()
                                    var email = $("[name='email']").val()
                                    var phone = $("[name='phone']").val()
                                    var address = $("[name='address']").val()
                                    var fax = $("[name='fax']").val()

                                    $.get("subinfo/addInfo",
                                        {
                                            "edirname": edirname,
                                            "uniformcode": uniformcode,
                                            "scale": scale,
                                            "email": email,
                                            "phone": phone,
                                            "fax": fax,
                                            "address": address
                                        },
                                        function (boo) {
                                            JSON.stringify(boo)
                                            if (boo) {
                                                alert("添加企业信息成功！")
                                            } else {
                                                alert("添加企业信息失败！")
                                            }
                                        })
                                })
                            }
                        })
                    }
                });

                /*控制点击移出后 如果值为空 出现警告*/
                {
                    $("[name='uniformcode']").blur(function () {
                        var uniformcode = $("[name='uniformcode']").val()
                        var label = $("#uniformcodelabel")
                        if (uniformcode.trim().length != 0) {
                            $("#uniformcodelabel").text(" ");
                            $("#uniformcodelabel").css("color", _green);
                        } else {
                            $("#uniformcodelabel").text("社会统一标码不允许为空！！请重新输入");
                            $("#uniformcodelabel").css("color", _red);
                        }
                    })

                    $("[name='scale']").blur(function () {
                        var scale = $("[name='scale']").val()
                        var label = $("#scalelabel")
                        if (scale.trim().length == 0) {
                            label.text("企业规模不允许为空！！请重新输入");
                            label.css("color", _red);
                        } else {
                            label.text(" ");
                            label.css("color", _green);
                        }
                    })

                    $("[name='email']").blur(function () {
                        var email = $("[name='email']").val()
                        var label = $("#emaillabel")
                        var leg = /^[a-zA-Z0-9]+@[a-zA-Z0-9]+\.(com|cn)$/;
                        if (email.trim().length != 0 && leg.test(email)) {
                            label.text(" ");
                            label.css("color", _green);
                        } else {
                            if (email.trim().length == 0) {
                                label.text("邮箱不允许为空！！请重新输入");
                                label.css("color", _red);
                            } else {
                                label.text("您输入的邮箱格式错误 请重新输入");
                                label.css("color", _red);
                            }
                        }
                    })

                    $("[name='phone']").blur(function () {
                        var phone = $("[name='phone']").val()
                        var label = $("#phonelabel")
                        if (phone.trim().length != 0) {
                            label.text(" ");
                            label.css("color", _green);
                        } else {
                            label.text("电话号码不允许为空！！请重新输入");
                            label.css("color", _red);
                        }
                    })

                    $("[name='fax']").blur(function () {
                        var fax = $("[name='fax']").val()
                        var label = $("#faxlabel")
                        if (fax.trim().length != 0) {
                            label.text(" ");
                            label.css("color", _green);
                        } else {
                            label.text("传真号码不允许为空！！请重新输入");
                            label.css("color", _red);
                        }
                    })

                    $("[name='address']").blur(function () {
                        var address = $("[name='address']").val()
                        var label = $("#addresslabel")
                        if (address.trim().length != 0) {
                            label.text(" ");
                            label.css("color", _green);
                        } else {
                            label.text("地址不允许为空！！请重新输入");
                            label.css("color", _red);
                        }
                    })
                }
            }
        });
    </script>
    <style>
        #targetModule {
            display: none;
        }

        #targetModule1 {
            display: none;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="header">
        <h1>企业认证</h1>
        <a href="index.jsp" class="logout-link">退出当前账户</a>
    </div>

    <div class="user-info">
        当前用户：<em name="loginaccount"><%=request.getParameter("account")%></em>
    </div>

    <div class="section">
        <div class="section-title">企业管理</div>
        <button id="toggleBtn" class="button">企业管理</button>

        <div id="targetModule" class="module">
            <button>企业信息认证</button>
        </div>
    </div>

    <div class="section">
        <div class="section-title">企业管理员认证</div>
        <table>
            <tr>
                <td>登录账号：</td>
                <td><em name="account"><%=request.getParameter("account")%></em></td>
            </tr>
            <tr>
                <td>管理员手机账号：</td>
                <td><i name="userphone"></i></td>
            </tr>
            <tr>
                <td>管理员姓名：</td>
                <td><input type="text" name="username" placeholder="请输入管理员姓名"></td>
            </tr>
            <tr>
                <td>管理员身份证号：</td>
                <td><input type="text" name="idcard" placeholder="请输入管理员身份证号"></td>
            </tr>
        </table>
    </div>

    <div class="section">
        <div class="section-title">企业信息</div>
        <table>
            <tr>
                <td>企业名称：</td>
                <td>
                    <input name="edirname" type="text" placeholder="请输入企业名称">
                    <label id="edirnamelabel" name="label"></label>
                </td>
            </tr>
            <tr>
                <td>统一社会信用代码：</td>
                <td>
                    <input name="uniformcode" type="text" placeholder="请输入统一社会信用代码">
                    <label id="uniformcodelabel" name="label"></label>
                </td>
            </tr>
            <tr>
                <td>企业规模：</td>
                <td>
                    <select name="scale">
                        <option value="-1" checked>请选择企业规模</option>
                        <option value="A">A</option>
                        <option value="B">B</option>
                        <option value="C">C</option>
                        <option value="D">D</option>
                        <option value="E">E</option>
                    </select>
                    <label id="scalelabel" name="label"></label>
                </td>
            </tr>
            <tr>
                <td>企业邮箱：</td>
                <td>
                    <input name="email" type="text" placeholder="请输入企业邮箱">
                    <label id="emaillabel" name="label"></label>
                </td>
            </tr>
            <tr>
                <td>企业电话：</td>
                <td>
                    <input name="phone" type="text" placeholder="请输入企业电话">
                    <label id="phonelabel" name="label"></label>
                </td>
            </tr>
            <tr>
                <td>传真：</td>
                <td>
                    <input name="fax" type="text" placeholder="请输入传真">
                    <label id="faxlabel" name="label"></label>
                </td>
            </tr>
            <tr>
                <td>企业注册详细地址：</td>
                <td>
                    <textarea name="address" placeholder="请输入企业注册详细地址"></textarea>
                    <label id="addresslabel" name="label"></label>
                </td>
            </tr>
        </table>

        <input type="submit" name="submitinfo" value="提交" class="submit-btn">
    </div>

    <div class="section">
        <div class="section-title">供应商管理</div>
        <button id="showModuleBtn" class="button">供应商管理</button>

        <div id="targetModule1" class="module">
            <button name="whitebutton" class="button">供应商白名单</button>
            <button name="blackbutton" class="button">供应商黑名单</button>
        </div>
    </div>
</div>
</body>
</html>